﻿namespace Code2Table.Core;

public static class TypeMapper
{
    private static readonly Dictionary<string, string> _map = new()
    {
        { "string", "VARCHAR(255)" },
        { "int", "INT" },
        { "long", "BIGINT" },
        { "short", "SMALLINT" },
        { "bool", "TINYINT(1)" },
        { "byte", "TINYINT UNSIGNED" },
        { "DateTime", "DATETIME" },
        { "decimal", "DECIMAL(18,2)" },
        { "double", "DOUBLE" },
        { "float", "FLOAT" },
        { "Guid", "CHAR(36)" }
    };

    /// <summary>
    /// 将 C# 类型映射为 MySQL 类型
    /// </summary>
    public static string MapToMySql(string csharpType)
    {
        // 去除可空符号（如 int? -> int）
        csharpType = csharpType.TrimEnd('?');

        if (_map.TryGetValue(csharpType, out var mapped))
            return mapped;

        return csharpType; // 默认返回原类型
    }

}